import React from 'react';

export default class RVue extends React.Component {
  handleChange(e) {
    this.data.value = e.target.value;
    console.log(this.data);
  }

  render() {
    return <input value={this.inner.value} onChange={this.handleChange} />;
  }

  constructor(props) {
    super(props);
    this.inner = {};
    const self = this;
    this.data = new Proxy(this.inner, {
      set(target, key, value) {
        const res = { [key]: value };
        if (self.state) self.setState(res);
        else {
          self.state = res;
        }
        self.inner[key] = value;
        // console.log(self.state, key, value, res);
        return true;
      },
    });
    this.data.value = props.value;
    this.handleChange = this.handleChange.bind(this);
  }
}
